/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.BasicComponents;

// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.MetaTypedList;
import edu.pku.sei.modeler.model.uml.Dependencies.Realization;
import edu.pku.sei.modeler.model.uml.Interfaces.Interface;
import edu.pku.sei.modeler.model.uml.Kernel.UMLPackage;
import edu.pku.sei.modeler.model.uml.StructuredClasses.StructuredClass;
import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;

/**
 * @generated
 * 
 */
public class Component extends StructuredClass implements IComponent {
	// attributes

	protected boolean isIndirectlyInstantiated;

	protected UMLPackage structuredPackage;

	// references

	public UMLPackage getStructuredPackage() {
		return structuredPackage;
	}

	public void setStructuredPackage(UMLPackage structuredPackage) {
		this.structuredPackage = structuredPackage;
	}

	protected MetaTypedList required;

	protected MetaTypedList provided;

	protected MetaTypedList realization;

	protected MetaTypedList nestedInterface;

	// getters & setters for attributes

	@MethodProperty(id = "COMPONENT_ISINDIRECTLYINSTANTIATED", catalog = "Model", name = ModelPackage.COMPONENT_ISINDIRECTLYINSTANTIATED, setter = "setisIndirectlyInstantiated")
	public boolean getIsIndirectlyInstantiated() {
		return isIndirectlyInstantiated;
	}

	public void setIsIndirectlyInstantiated(boolean newIsIndirectlyInstantiated) {
		boolean oldisIndirectlyInstantiated = isIndirectlyInstantiated;
		isIndirectlyInstantiated = newIsIndirectlyInstantiated;
		firePropertyChange(ModelPackage.COMPONENT_ISINDIRECTLYINSTANTIATED,
				oldisIndirectlyInstantiated, newIsIndirectlyInstantiated);
	}

	// getters for references

	// public MetaTypedList getPorts() {
	// if(ports == null) {
	// ports = new MetaTypedList(Port.class, this,
	// ModelPackage.COMPONENT_PORTS);
	// }
	// return ports;
	// }

	public MetaTypedList getRequired() {
		if (required == null) {
			required = new MetaTypedList(Interface.class, this,
					ModelPackage.COMPONENT_REQUIRED);
		}
		return required;
	}

	public MetaTypedList getProvided() {
		if (provided == null) {
			provided = new MetaTypedList(Interface.class, this,
					ModelPackage.COMPONENT_PROVIDED);
		}
		return provided;
	}

	public MetaTypedList getRealization() {
		if (realization == null) {
			realization = new MetaTypedList(Realization.class, this,
					ModelPackage.COMPONENT_REALIZATION);
		}
		return realization;
	}

	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes

		XMLUtility.xmlInstance.serializeAttribute(root,
				ModelPackage.COMPONENT_ISINDIRECTLYINSTANTIATED,
				isIndirectlyInstantiated);

		// references

		XMLUtility.xmlInstance.serializeNodesNotContain(root,
				ModelPackage.COMPONENT_REQUIRED, required);

		XMLUtility.xmlInstance.serializeNodesNotContain(root,
				ModelPackage.COMPONENT_PROVIDED, provided);

		XMLUtility.xmlInstance.serializeNodes(root,
				ModelPackage.COMPONENT_REALIZATION, realization);

		XMLUtility.xmlInstance.serializeNodes(root,
				ModelPackage.COMPONENT_NESTEDINTERFACE, nestedInterface);

		XMLUtility.xmlInstance.serializeNodeNotContain(root,
				ModelPackage.COMPONENT_STRUCTUREDPACKAGE,
				this.structuredPackage);

	}

	public MetaTypedList getNestedInterface() {
		if (nestedInterface == null) {
			nestedInterface = new MetaTypedList(Interface.class, this,
					ModelPackage.COMPONENT_NESTEDINTERFACE);
		}
		return nestedInterface;
	}

	public void setNestedInterface(MetaTypedList nestedInterface) {
		this.nestedInterface = nestedInterface;
	}

	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes

		isIndirectlyInstantiated = XMLUtility.xmlInstance.deSerializeBoolean(
				root, ModelPackage.COMPONENT_ISINDIRECTLYINSTANTIATED);

		// references

		this.getRequired().addAll(
				XMLUtility.xmlInstance.deSerializeNodesNotContain(root,
						ModelPackage.COMPONENT_REQUIRED, this));

		this.getProvided().addAll(
				XMLUtility.xmlInstance.deSerializeNodesNotContain(root,
						ModelPackage.COMPONENT_PROVIDED, this));

		this.getRealization().addAll(
				XMLUtility.xmlInstance.deSerializeNodes(root,
						ModelPackage.COMPONENT_REALIZATION));

		this.getNestedInterface().addAll(
				XMLUtility.xmlInstance.deSerializeNodes(root,
						ModelPackage.COMPONENT_NESTEDINTERFACE));

		this.structuredPackage = (UMLPackage) XMLUtility.xmlInstance
				.deSerializeNodeNotContain(root,
						ModelPackage.COMPONENT_STRUCTUREDPACKAGE, this);
	}

	public void dynamicSet(String featureID, Object value) {
		if (featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes

		// references

		else if (ModelPackage.COMPONENT_REQUIRED.equals(featureID)) {
			getRequired().add(value);
		}

		else if (ModelPackage.COMPONENT_PROVIDED.equals(featureID)) {
			getProvided().add(value);
		}

		else if (ModelPackage.COMPONENT_STRUCTUREDPACKAGE.equals(featureID)) {
			this.structuredPackage = (UMLPackage) value;
		} else
			super.dynamicSet(featureID, value);
	}
}
